home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / ASM 2.0 ƒ / table.awk < prev    next >
Encoding:
AWK Script  |  1992-06-15  |  805 b   |  42 lines

  1. #
  2. #       convert mnemonic/templates to C structures
  3. #
  4. BEGIN{
  5.     print "#include \"table.h\""
  6.     print
  7.     print "struct tmpl template[] = {"
  8. }
  9.  
  10. {
  11.     if( NF == 0 )
  12.         ;
  13.     else if( NF == 1 ){             # a new mnemonic
  14.         nmne++
  15.         mne[nmne] = $1
  16.         tidx[nmne] = lastidx
  17.         }
  18.     else{                           # a template
  19.         if( NF == 4 )
  20.             lastf = "0"
  21.         else
  22.             lastf = $5
  23.         printf "{ %s, {%s}, %s, 0x%s, 0x%s },", $1, $2, $3, $4, lastf
  24.         if( tidx[nmne] == lastidx )
  25.             printf "        /* %d = %s */\n", lastidx, mne[nmne]
  26.         else
  27.             printf "\n"
  28.         tcount[nmne]++
  29.         lastidx++
  30.         }
  31. }
  32.  
  33. END{
  34.     print "};"
  35.     print
  36.     printf "/*  %d mnemonics, %d templates  */\n",nmne,lastidx
  37.     print
  38.     print "struct mne mnemonic[] = {"
  39.     for(i=1;i<=nmne;i++)
  40.         printf "\"%s\", %d, &template[%d],\n", mne[i], tcount[i], tidx[i] | "sort >mne.sort"
  41. }
  42.